<html><!-- Created using the cpp_pretty_printer from the dlib C++ library.  See http://dlib.net for updates. --><head><title>dlib C++ Library - interpolation.h</title></head><body bgcolor='white'><pre>
<font color='#009900'>// Copyright (C) 2012  Davis E. King (davis@dlib.net)
</font><font color='#009900'>// License: Boost Software License   See LICENSE.txt for the full license.
</font><font color='#0000FF'>#ifndef</font> DLIB_INTERPOlATION__
<font color='#0000FF'>#define</font> DLIB_INTERPOlATION__ 

<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='interpolation_abstract.h.html'>interpolation_abstract.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../pixel.h.html'>../pixel.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../matrix.h.html'>../matrix.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='assign_image.h.html'>assign_image.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='image_pyramid.h.html'>image_pyramid.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../simd.h.html'>../simd.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../image_processing/full_object_detection.h.html'>../image_processing/full_object_detection.h</a>"

<font color='#0000FF'>namespace</font> dlib
<b>{</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>class</font> <b><a name='interpolate_nearest_neighbor'></a>interpolate_nearest_neighbor</b>
    <b>{</b>
    <font color='#0000FF'>public</font>:

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> image_type, <font color='#0000FF'>typename</font> pixel_type<font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>bool</u></font> <b><a name='operator'></a>operator</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> image_type<font color='#5555FF'>&amp;</font> img,
            <font color='#0000FF'>const</font> dlib::point<font color='#5555FF'>&amp;</font> p,
            pixel_type<font color='#5555FF'>&amp;</font> result
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b>
            <font color='#BB00BB'>COMPILE_TIME_ASSERT</font><font face='Lucida Console'>(</font>pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> image_type::type<font color='#5555FF'>&gt;</font>::has_alpha <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>;

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font>img<font face='Lucida Console'>)</font>.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>p<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>result, img[p.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>][p.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>]<font face='Lucida Console'>)</font>;
                <font color='#0000FF'>return</font> <font color='#979000'>true</font>;
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>
                <font color='#0000FF'>return</font> <font color='#979000'>false</font>;
            <b>}</b>
        <b>}</b>

    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>class</font> <b><a name='interpolate_bilinear'></a>interpolate_bilinear</b>
    <b>{</b>
        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> T<font color='#5555FF'>&gt;</font>
        <font color='#0000FF'>struct</font> <b><a name='is_rgb_image'></a>is_rgb_image</b> 
        <b>{</b>
            <font color='#0000FF'>const</font> <font color='#0000FF'>static</font> <font color='#0000FF'><u>bool</u></font> value <font color='#5555FF'>=</font> pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> T::type<font color='#5555FF'>&gt;</font>::rgb;
        <b>}</b>;

    <font color='#0000FF'>public</font>:

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> T, <font color='#0000FF'>typename</font> image_type, <font color='#0000FF'>typename</font> pixel_type<font color='#5555FF'>&gt;</font>
        <font color='#0000FF'>typename</font> disable_if<font color='#5555FF'>&lt;</font>is_rgb_image<font color='#5555FF'>&lt;</font>image_type<font color='#5555FF'>&gt;</font>,<font color='#0000FF'><u>bool</u></font><font color='#5555FF'>&gt;</font>::type <b><a name='operator'></a>operator</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> image_type<font color='#5555FF'>&amp;</font> img,
            <font color='#0000FF'>const</font> dlib::vector<font color='#5555FF'>&lt;</font>T,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> p,
            pixel_type<font color='#5555FF'>&amp;</font> result
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b>
            <font color='#BB00BB'>COMPILE_TIME_ASSERT</font><font face='Lucida Console'>(</font>pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> image_type::type<font color='#5555FF'>&gt;</font>::has_alpha <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>;

            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> left   <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>floor</font><font face='Lucida Console'>(</font>p.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> top    <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>floor</font><font face='Lucida Console'>(</font>p.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> right  <font color='#5555FF'>=</font> left<font color='#5555FF'>+</font><font color='#979000'>1</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> bottom <font color='#5555FF'>=</font> top<font color='#5555FF'>+</font><font color='#979000'>1</font>;


            <font color='#009900'>// if the interpolation goes outside img 
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font><font face='Lucida Console'>(</font>left <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> top <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> right <font color='#5555FF'>&lt;</font> img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> bottom <font color='#5555FF'>&lt;</font> img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#0000FF'>return</font> <font color='#979000'>false</font>;

            <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> lr_frac <font color='#5555FF'>=</font> p.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> left;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> tb_frac <font color='#5555FF'>=</font> p.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> top;

            <font color='#0000FF'><u>double</u></font> tl <font color='#5555FF'>=</font> <font color='#979000'>0</font>, tr <font color='#5555FF'>=</font> <font color='#979000'>0</font>, bl <font color='#5555FF'>=</font> <font color='#979000'>0</font>, br <font color='#5555FF'>=</font> <font color='#979000'>0</font>;

            <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>tl, img[top][left]<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>tr, img[top][right]<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>bl, img[bottom][left]<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>br, img[bottom][right]<font face='Lucida Console'>)</font>;
            
            <font color='#0000FF'><u>double</u></font> temp <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#979000'>1</font><font color='#5555FF'>-</font>tb_frac<font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font color='#5555FF'>-</font>lr_frac<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>tl <font color='#5555FF'>+</font> lr_frac<font color='#5555FF'>*</font>tr<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> 
                              tb_frac<font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font color='#5555FF'>-</font>lr_frac<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>bl <font color='#5555FF'>+</font> lr_frac<font color='#5555FF'>*</font>br<font face='Lucida Console'>)</font>;
                            
            <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>result, temp<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font> <font color='#979000'>true</font>;
        <b>}</b>

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> T, <font color='#0000FF'>typename</font> image_type, <font color='#0000FF'>typename</font> pixel_type<font color='#5555FF'>&gt;</font>
        <font color='#0000FF'>typename</font> enable_if<font color='#5555FF'>&lt;</font>is_rgb_image<font color='#5555FF'>&lt;</font>image_type<font color='#5555FF'>&gt;</font>,<font color='#0000FF'><u>bool</u></font><font color='#5555FF'>&gt;</font>::type <b><a name='operator'></a>operator</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> image_type<font color='#5555FF'>&amp;</font> img,
            <font color='#0000FF'>const</font> dlib::vector<font color='#5555FF'>&lt;</font>T,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> p,
            pixel_type<font color='#5555FF'>&amp;</font> result
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b>
            <font color='#BB00BB'>COMPILE_TIME_ASSERT</font><font face='Lucida Console'>(</font>pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> image_type::type<font color='#5555FF'>&gt;</font>::has_alpha <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>;

            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> left   <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>floor</font><font face='Lucida Console'>(</font>p.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> top    <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>floor</font><font face='Lucida Console'>(</font>p.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> right  <font color='#5555FF'>=</font> left<font color='#5555FF'>+</font><font color='#979000'>1</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> bottom <font color='#5555FF'>=</font> top<font color='#5555FF'>+</font><font color='#979000'>1</font>;


            <font color='#009900'>// if the interpolation goes outside img 
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font><font face='Lucida Console'>(</font>left <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> top <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> right <font color='#5555FF'>&lt;</font> img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> bottom <font color='#5555FF'>&lt;</font> img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#0000FF'>return</font> <font color='#979000'>false</font>;

            <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> lr_frac <font color='#5555FF'>=</font> p.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> left;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> tb_frac <font color='#5555FF'>=</font> p.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> top;

            <font color='#0000FF'><u>double</u></font> tl, tr, bl, br;

            tl <font color='#5555FF'>=</font> img[top][left].red;
            tr <font color='#5555FF'>=</font> img[top][right].red;
            bl <font color='#5555FF'>=</font> img[bottom][left].red;
            br <font color='#5555FF'>=</font> img[bottom][right].red;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> red <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#979000'>1</font><font color='#5555FF'>-</font>tb_frac<font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font color='#5555FF'>-</font>lr_frac<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>tl <font color='#5555FF'>+</font> lr_frac<font color='#5555FF'>*</font>tr<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> 
                                   tb_frac<font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font color='#5555FF'>-</font>lr_frac<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>bl <font color='#5555FF'>+</font> lr_frac<font color='#5555FF'>*</font>br<font face='Lucida Console'>)</font>;

            tl <font color='#5555FF'>=</font> img[top][left].green;
            tr <font color='#5555FF'>=</font> img[top][right].green;
            bl <font color='#5555FF'>=</font> img[bottom][left].green;
            br <font color='#5555FF'>=</font> img[bottom][right].green;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> green <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#979000'>1</font><font color='#5555FF'>-</font>tb_frac<font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font color='#5555FF'>-</font>lr_frac<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>tl <font color='#5555FF'>+</font> lr_frac<font color='#5555FF'>*</font>tr<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> 
                                   tb_frac<font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font color='#5555FF'>-</font>lr_frac<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>bl <font color='#5555FF'>+</font> lr_frac<font color='#5555FF'>*</font>br<font face='Lucida Console'>)</font>;

            tl <font color='#5555FF'>=</font> img[top][left].blue;
            tr <font color='#5555FF'>=</font> img[top][right].blue;
            bl <font color='#5555FF'>=</font> img[bottom][left].blue;
            br <font color='#5555FF'>=</font> img[bottom][right].blue;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> blue <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#979000'>1</font><font color='#5555FF'>-</font>tb_frac<font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font color='#5555FF'>-</font>lr_frac<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>tl <font color='#5555FF'>+</font> lr_frac<font color='#5555FF'>*</font>tr<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> 
                                   tb_frac<font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font color='#5555FF'>-</font>lr_frac<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>bl <font color='#5555FF'>+</font> lr_frac<font color='#5555FF'>*</font>br<font face='Lucida Console'>)</font>;
                            
            rgb_pixel temp;
            <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>temp.red, red<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>temp.green, green<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>temp.blue, blue<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>result, temp<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font> <font color='#979000'>true</font>;
        <b>}</b>
    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>class</font> <b><a name='interpolate_quadratic'></a>interpolate_quadratic</b>
    <b>{</b>
        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> T<font color='#5555FF'>&gt;</font>
        <font color='#0000FF'>struct</font> <b><a name='is_rgb_image'></a>is_rgb_image</b> 
        <b>{</b>
            <font color='#0000FF'>const</font> <font color='#0000FF'>static</font> <font color='#0000FF'><u>bool</u></font> value <font color='#5555FF'>=</font> pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> T::type<font color='#5555FF'>&gt;</font>::rgb;
        <b>}</b>;

    <font color='#0000FF'>public</font>:

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> T, <font color='#0000FF'>typename</font> image_type, <font color='#0000FF'>typename</font> pixel_type<font color='#5555FF'>&gt;</font>
        <font color='#0000FF'>typename</font> disable_if<font color='#5555FF'>&lt;</font>is_rgb_image<font color='#5555FF'>&lt;</font>image_type<font color='#5555FF'>&gt;</font>,<font color='#0000FF'><u>bool</u></font><font color='#5555FF'>&gt;</font>::type <b><a name='operator'></a>operator</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> image_type<font color='#5555FF'>&amp;</font> img,
            <font color='#0000FF'>const</font> dlib::vector<font color='#5555FF'>&lt;</font>T,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> p,
            pixel_type<font color='#5555FF'>&amp;</font> result
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b>
            <font color='#BB00BB'>COMPILE_TIME_ASSERT</font><font face='Lucida Console'>(</font>pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> image_type::type<font color='#5555FF'>&gt;</font>::has_alpha <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>;

            <font color='#0000FF'>const</font> point <font color='#BB00BB'>pp</font><font face='Lucida Console'>(</font>p<font face='Lucida Console'>)</font>;

            <font color='#009900'>// if the interpolation goes outside img 
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font><font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font>img<font face='Lucida Console'>)</font>.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font><font color='#BB00BB'>grow_rect</font><font face='Lucida Console'>(</font>pp,<font color='#979000'>1</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> 
                <font color='#0000FF'>return</font> <font color='#979000'>false</font>;

            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> r <font color='#5555FF'>=</font> pp.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> c <font color='#5555FF'>=</font> pp.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> temp <font color='#5555FF'>=</font> <font color='#BB00BB'>interpolate</font><font face='Lucida Console'>(</font>p<font color='#5555FF'>-</font>pp, 
                                    img[r<font color='#5555FF'>-</font><font color='#979000'>1</font>][c<font color='#5555FF'>-</font><font color='#979000'>1</font>],
                                    img[r<font color='#5555FF'>-</font><font color='#979000'>1</font>][c  ],
                                    img[r<font color='#5555FF'>-</font><font color='#979000'>1</font>][c<font color='#5555FF'>+</font><font color='#979000'>1</font>],
                                    img[r  ][c<font color='#5555FF'>-</font><font color='#979000'>1</font>],
                                    img[r  ][c  ],
                                    img[r  ][c<font color='#5555FF'>+</font><font color='#979000'>1</font>],
                                    img[r<font color='#5555FF'>+</font><font color='#979000'>1</font>][c<font color='#5555FF'>-</font><font color='#979000'>1</font>],
                                    img[r<font color='#5555FF'>+</font><font color='#979000'>1</font>][c  ],
                                    img[r<font color='#5555FF'>+</font><font color='#979000'>1</font>][c<font color='#5555FF'>+</font><font color='#979000'>1</font>]<font face='Lucida Console'>)</font>;

            <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>result, temp<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font> <font color='#979000'>true</font>;
        <b>}</b>

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> T, <font color='#0000FF'>typename</font> image_type, <font color='#0000FF'>typename</font> pixel_type<font color='#5555FF'>&gt;</font>
        <font color='#0000FF'>typename</font> enable_if<font color='#5555FF'>&lt;</font>is_rgb_image<font color='#5555FF'>&lt;</font>image_type<font color='#5555FF'>&gt;</font>,<font color='#0000FF'><u>bool</u></font><font color='#5555FF'>&gt;</font>::type <b><a name='operator'></a>operator</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> image_type<font color='#5555FF'>&amp;</font> img,
            <font color='#0000FF'>const</font> dlib::vector<font color='#5555FF'>&lt;</font>T,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> p,
            pixel_type<font color='#5555FF'>&amp;</font> result
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b>
            <font color='#BB00BB'>COMPILE_TIME_ASSERT</font><font face='Lucida Console'>(</font>pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> image_type::type<font color='#5555FF'>&gt;</font>::has_alpha <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>;

            <font color='#0000FF'>const</font> point <font color='#BB00BB'>pp</font><font face='Lucida Console'>(</font>p<font face='Lucida Console'>)</font>;

            <font color='#009900'>// if the interpolation goes outside img 
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font><font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font>img<font face='Lucida Console'>)</font>.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font><font color='#BB00BB'>grow_rect</font><font face='Lucida Console'>(</font>pp,<font color='#979000'>1</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> 
                <font color='#0000FF'>return</font> <font color='#979000'>false</font>;

            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> r <font color='#5555FF'>=</font> pp.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> c <font color='#5555FF'>=</font> pp.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> red <font color='#5555FF'>=</font> <font color='#BB00BB'>interpolate</font><font face='Lucida Console'>(</font>p<font color='#5555FF'>-</font>pp, 
                            img[r<font color='#5555FF'>-</font><font color='#979000'>1</font>][c<font color='#5555FF'>-</font><font color='#979000'>1</font>].red,
                            img[r<font color='#5555FF'>-</font><font color='#979000'>1</font>][c  ].red,
                            img[r<font color='#5555FF'>-</font><font color='#979000'>1</font>][c<font color='#5555FF'>+</font><font color='#979000'>1</font>].red,
                            img[r  ][c<font color='#5555FF'>-</font><font color='#979000'>1</font>].red,
                            img[r  ][c  ].red,
                            img[r  ][c<font color='#5555FF'>+</font><font color='#979000'>1</font>].red,
                            img[r<font color='#5555FF'>+</font><font color='#979000'>1</font>][c<font color='#5555FF'>-</font><font color='#979000'>1</font>].red,
                            img[r<font color='#5555FF'>+</font><font color='#979000'>1</font>][c  ].red,
                            img[r<font color='#5555FF'>+</font><font color='#979000'>1</font>][c<font color='#5555FF'>+</font><font color='#979000'>1</font>].red<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> green <font color='#5555FF'>=</font> <font color='#BB00BB'>interpolate</font><font face='Lucida Console'>(</font>p<font color='#5555FF'>-</font>pp, 
                            img[r<font color='#5555FF'>-</font><font color='#979000'>1</font>][c<font color='#5555FF'>-</font><font color='#979000'>1</font>].green,
                            img[r<font color='#5555FF'>-</font><font color='#979000'>1</font>][c  ].green,
                            img[r<font color='#5555FF'>-</font><font color='#979000'>1</font>][c<font color='#5555FF'>+</font><font color='#979000'>1</font>].green,
                            img[r  ][c<font color='#5555FF'>-</font><font color='#979000'>1</font>].green,
                            img[r  ][c  ].green,
                            img[r  ][c<font color='#5555FF'>+</font><font color='#979000'>1</font>].green,
                            img[r<font color='#5555FF'>+</font><font color='#979000'>1</font>][c<font color='#5555FF'>-</font><font color='#979000'>1</font>].green,
                            img[r<font color='#5555FF'>+</font><font color='#979000'>1</font>][c  ].green,
                            img[r<font color='#5555FF'>+</font><font color='#979000'>1</font>][c<font color='#5555FF'>+</font><font color='#979000'>1</font>].green<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> blue <font color='#5555FF'>=</font> <font color='#BB00BB'>interpolate</font><font face='Lucida Console'>(</font>p<font color='#5555FF'>-</font>pp, 
                            img[r<font color='#5555FF'>-</font><font color='#979000'>1</font>][c<font color='#5555FF'>-</font><font color='#979000'>1</font>].blue,
                            img[r<font color='#5555FF'>-</font><font color='#979000'>1</font>][c  ].blue,
                            img[r<font color='#5555FF'>-</font><font color='#979000'>1</font>][c<font color='#5555FF'>+</font><font color='#979000'>1</font>].blue,
                            img[r  ][c<font color='#5555FF'>-</font><font color='#979000'>1</font>].blue,
                            img[r  ][c  ].blue,
                            img[r  ][c<font color='#5555FF'>+</font><font color='#979000'>1</font>].blue,
                            img[r<font color='#5555FF'>+</font><font color='#979000'>1</font>][c<font color='#5555FF'>-</font><font color='#979000'>1</font>].blue,
                            img[r<font color='#5555FF'>+</font><font color='#979000'>1</font>][c  ].blue,
                            img[r<font color='#5555FF'>+</font><font color='#979000'>1</font>][c<font color='#5555FF'>+</font><font color='#979000'>1</font>].blue<font face='Lucida Console'>)</font>;


            rgb_pixel temp;
            <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>temp.red, red<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>temp.green, green<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>temp.blue, blue<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>result, temp<font face='Lucida Console'>)</font>;

            <font color='#0000FF'>return</font> <font color='#979000'>true</font>;
        <b>}</b>

    <font color='#0000FF'>private</font>:

        <font color='#009900'>/*  tl tm tr
            ml mm mr
            bl bm br
        */</font>
        <font color='#009900'>// The above is the pixel layout in our little 3x3 neighborhood.  interpolate() will 
</font>        <font color='#009900'>// fit a quadratic to these 9 pixels and then use that quadratic to find the interpolated 
</font>        <font color='#009900'>// value at point p.
</font>        <font color='#0000FF'>inline</font> <font color='#0000FF'><u>double</u></font> <b><a name='interpolate'></a>interpolate</b><font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> dlib::vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> p,
            <font color='#0000FF'><u>double</u></font> tl, <font color='#0000FF'><u>double</u></font> tm, <font color='#0000FF'><u>double</u></font> tr, 
            <font color='#0000FF'><u>double</u></font> ml, <font color='#0000FF'><u>double</u></font> mm, <font color='#0000FF'><u>double</u></font> mr, 
            <font color='#0000FF'><u>double</u></font> bl, <font color='#0000FF'><u>double</u></font> bm, <font color='#0000FF'><u>double</u></font> br
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b>
            matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>6</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> w;
            <font color='#009900'>// x
</font>            <font color='#BB00BB'>w</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>tr <font color='#5555FF'>+</font> mr <font color='#5555FF'>+</font> br <font color='#5555FF'>-</font> tl <font color='#5555FF'>-</font> ml <font color='#5555FF'>-</font> bl<font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>0.16666666666</font>;
            <font color='#009900'>// y
</font>            <font color='#BB00BB'>w</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>bl <font color='#5555FF'>+</font> bm <font color='#5555FF'>+</font> br <font color='#5555FF'>-</font> tl <font color='#5555FF'>-</font> tm <font color='#5555FF'>-</font> tr<font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>0.16666666666</font>;
            <font color='#009900'>// x^2
</font>            <font color='#BB00BB'>w</font><font face='Lucida Console'>(</font><font color='#979000'>2</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>tl <font color='#5555FF'>+</font> tr <font color='#5555FF'>+</font> ml <font color='#5555FF'>+</font> mr <font color='#5555FF'>+</font> bl <font color='#5555FF'>+</font> br<font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>0.16666666666</font> <font color='#5555FF'>-</font> <font face='Lucida Console'>(</font>tm <font color='#5555FF'>+</font> mm <font color='#5555FF'>+</font> bm<font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>0.333333333</font>;
            <font color='#009900'>// x*y
</font>            <font color='#BB00BB'>w</font><font face='Lucida Console'>(</font><font color='#979000'>3</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>tl <font color='#5555FF'>-</font> tr <font color='#5555FF'>-</font> bl <font color='#5555FF'>+</font> br<font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>0.25</font>;
            <font color='#009900'>// y^2
</font>            <font color='#BB00BB'>w</font><font face='Lucida Console'>(</font><font color='#979000'>4</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>tl <font color='#5555FF'>+</font> tm <font color='#5555FF'>+</font> tr <font color='#5555FF'>+</font> bl <font color='#5555FF'>+</font> bm <font color='#5555FF'>+</font> br<font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>0.16666666666</font> <font color='#5555FF'>-</font> <font face='Lucida Console'>(</font>ml <font color='#5555FF'>+</font> mm <font color='#5555FF'>+</font> mr<font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>0.333333333</font>;
            <font color='#009900'>// 1 (constant term)
</font>            <font color='#BB00BB'>w</font><font face='Lucida Console'>(</font><font color='#979000'>5</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>tm <font color='#5555FF'>+</font> ml <font color='#5555FF'>+</font> mr <font color='#5555FF'>+</font> bm<font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>0.222222222</font> <font color='#5555FF'>-</font> <font face='Lucida Console'>(</font>tl <font color='#5555FF'>+</font> tr <font color='#5555FF'>+</font> bl <font color='#5555FF'>+</font> br<font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>0.11111111</font> <font color='#5555FF'>+</font> <font face='Lucida Console'>(</font>mm<font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>0.55555556</font>;

            <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> x <font color='#5555FF'>=</font> p.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> y <font color='#5555FF'>=</font> p.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>6</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font> z;
            z <font color='#5555FF'>=</font> x, y, x<font color='#5555FF'>*</font>x, x<font color='#5555FF'>*</font>y, y<font color='#5555FF'>*</font>y, <font color='#979000'>1.0</font>;
                            
            <font color='#0000FF'>return</font> <font color='#BB00BB'>dot</font><font face='Lucida Console'>(</font>w,z<font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>class</font> <b><a name='black_background'></a>black_background</b>
    <b>{</b>
    <font color='#0000FF'>public</font>:
        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> pixel_type<font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='operator'></a>operator</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font> pixel_type<font color='#5555FF'>&amp;</font> p<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> <b>{</b> <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>p, <font color='#979000'>0</font><font face='Lucida Console'>)</font>; <b>}</b>
    <b>}</b>;

    <font color='#0000FF'>class</font> <b><a name='white_background'></a>white_background</b>
    <b>{</b>
    <font color='#0000FF'>public</font>:
        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> pixel_type<font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='operator'></a>operator</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font> pixel_type<font color='#5555FF'>&amp;</font> p<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> <b>{</b> <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>p, <font color='#979000'>255</font><font face='Lucida Console'>)</font>; <b>}</b>
    <b>}</b>;

    <font color='#0000FF'>class</font> <b><a name='no_background'></a>no_background</b>
    <b>{</b>
    <font color='#0000FF'>public</font>:
        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> pixel_type<font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='operator'></a>operator</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font> pixel_type<font color='#5555FF'>&amp;</font> <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> <b>{</b> <b>}</b>
    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type1,
        <font color='#0000FF'>typename</font> image_type2,
        <font color='#0000FF'>typename</font> interpolation_type,
        <font color='#0000FF'>typename</font> point_mapping_type,
        <font color='#0000FF'>typename</font> background_type
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='transform_image'></a>transform_image</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> image_type1<font color='#5555FF'>&amp;</font> in_img,
        image_type2<font color='#5555FF'>&amp;</font> out_img,
        <font color='#0000FF'>const</font> interpolation_type<font color='#5555FF'>&amp;</font> interp,
        <font color='#0000FF'>const</font> point_mapping_type<font color='#5555FF'>&amp;</font> map_point,
        <font color='#0000FF'>const</font> background_type<font color='#5555FF'>&amp;</font> set_background,
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> area
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// make sure requires clause is not broken
</font>        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font> <font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font>out_img<font face='Lucida Console'>)</font>.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>area<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>true</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                     <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> ,
            "<font color='#CC0000'>\t void transform_image()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid inputs were given to this function.</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t get_rect(out_img).contains(area): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font>out_img<font face='Lucida Console'>)</font>.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>area<font face='Lucida Console'>)</font>
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t get_rect(out_img): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font>out_img<font face='Lucida Console'>)</font>
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t area:              </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> area
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t is_same_object(in_img, out_img):  </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font>
            <font face='Lucida Console'>)</font>;


        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> r <font color='#5555FF'>=</font> area.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; r <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> area.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>r<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> c <font color='#5555FF'>=</font> area.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; c <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> area.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>c<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font><font color='#BB00BB'>interp</font><font face='Lucida Console'>(</font>in_img, <font color='#BB00BB'>map_point</font><font face='Lucida Console'>(</font>dlib::vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>c,r<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>, out_img[r][c]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                    <font color='#BB00BB'>set_background</font><font face='Lucida Console'>(</font>out_img[r][c]<font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type1,
        <font color='#0000FF'>typename</font> image_type2,
        <font color='#0000FF'>typename</font> interpolation_type,
        <font color='#0000FF'>typename</font> point_mapping_type,
        <font color='#0000FF'>typename</font> background_type
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='transform_image'></a>transform_image</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> image_type1<font color='#5555FF'>&amp;</font> in_img,
        image_type2<font color='#5555FF'>&amp;</font> out_img,
        <font color='#0000FF'>const</font> interpolation_type<font color='#5555FF'>&amp;</font> interp,
        <font color='#0000FF'>const</font> point_mapping_type<font color='#5555FF'>&amp;</font> map_point,
        <font color='#0000FF'>const</font> background_type<font color='#5555FF'>&amp;</font> set_background
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// make sure requires clause is not broken
</font>        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font> <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> ,
            "<font color='#CC0000'>\t void transform_image()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid inputs were given to this function.</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t is_same_object(in_img, out_img):  </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font>
            <font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>transform_image</font><font face='Lucida Console'>(</font>in_img, out_img, interp, map_point, set_background, <font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font>out_img<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type1,
        <font color='#0000FF'>typename</font> image_type2,
        <font color='#0000FF'>typename</font> interpolation_type,
        <font color='#0000FF'>typename</font> point_mapping_type
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='transform_image'></a>transform_image</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> image_type1<font color='#5555FF'>&amp;</font> in_img,
        image_type2<font color='#5555FF'>&amp;</font> out_img,
        <font color='#0000FF'>const</font> interpolation_type<font color='#5555FF'>&amp;</font> interp,
        <font color='#0000FF'>const</font> point_mapping_type<font color='#5555FF'>&amp;</font> map_point
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// make sure requires clause is not broken
</font>        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font> <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> ,
            "<font color='#CC0000'>\t void transform_image()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid inputs were given to this function.</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t is_same_object(in_img, out_img):  </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font>
            <font face='Lucida Console'>)</font>;


        <font color='#BB00BB'>transform_image</font><font face='Lucida Console'>(</font>in_img, out_img, interp, map_point, <font color='#BB00BB'>black_background</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font>out_img<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type1,
        <font color='#0000FF'>typename</font> image_type2,
        <font color='#0000FF'>typename</font> interpolation_type
        <font color='#5555FF'>&gt;</font>
    point_transform_affine <b><a name='rotate_image'></a>rotate_image</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> image_type1<font color='#5555FF'>&amp;</font> in_img,
        image_type2<font color='#5555FF'>&amp;</font> out_img,
        <font color='#0000FF'><u>double</u></font> angle,
        <font color='#0000FF'>const</font> interpolation_type<font color='#5555FF'>&amp;</font> interp
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// make sure requires clause is not broken
</font>        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font> <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> ,
            "<font color='#CC0000'>\t point_transform_affine rotate_image()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid inputs were given to this function.</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t is_same_object(in_img, out_img):  </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font>
            <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>const</font> rectangle rimg <font color='#5555FF'>=</font> <font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font>in_img<font face='Lucida Console'>)</font>;


        <font color='#009900'>// figure out bounding box for rotated rectangle
</font>        rectangle rect;
        rect <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#BB00BB'>rotate_point</font><font face='Lucida Console'>(</font><font color='#BB00BB'>center</font><font face='Lucida Console'>(</font>rimg<font face='Lucida Console'>)</font>, rimg.<font color='#BB00BB'>tl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, <font color='#5555FF'>-</font>angle<font face='Lucida Console'>)</font>;
        rect <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#BB00BB'>rotate_point</font><font face='Lucida Console'>(</font><font color='#BB00BB'>center</font><font face='Lucida Console'>(</font>rimg<font face='Lucida Console'>)</font>, rimg.<font color='#BB00BB'>tr_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, <font color='#5555FF'>-</font>angle<font face='Lucida Console'>)</font>;
        rect <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#BB00BB'>rotate_point</font><font face='Lucida Console'>(</font><font color='#BB00BB'>center</font><font face='Lucida Console'>(</font>rimg<font face='Lucida Console'>)</font>, rimg.<font color='#BB00BB'>bl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, <font color='#5555FF'>-</font>angle<font face='Lucida Console'>)</font>;
        rect <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#BB00BB'>rotate_point</font><font face='Lucida Console'>(</font><font color='#BB00BB'>center</font><font face='Lucida Console'>(</font>rimg<font face='Lucida Console'>)</font>, rimg.<font color='#BB00BB'>br_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, <font color='#5555FF'>-</font>angle<font face='Lucida Console'>)</font>;
        out_img.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#0000FF'>const</font> matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>2</font>,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font> R <font color='#5555FF'>=</font> <font color='#BB00BB'>rotation_matrix</font><font face='Lucida Console'>(</font>angle<font face='Lucida Console'>)</font>;

        point_transform_affine trans <font color='#5555FF'>=</font> <font color='#BB00BB'>point_transform_affine</font><font face='Lucida Console'>(</font>R, <font color='#5555FF'>-</font>R<font color='#5555FF'>*</font><font color='#BB00BB'>dcenter</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font>out_img<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>dcenter</font><font face='Lucida Console'>(</font>rimg<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>transform_image</font><font face='Lucida Console'>(</font>in_img, out_img, interp, trans<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> <font color='#BB00BB'>inv</font><font face='Lucida Console'>(</font>trans<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type1,
        <font color='#0000FF'>typename</font> image_type2
        <font color='#5555FF'>&gt;</font>
    point_transform_affine <b><a name='rotate_image'></a>rotate_image</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> image_type1<font color='#5555FF'>&amp;</font> in_img,
        image_type2<font color='#5555FF'>&amp;</font> out_img,
        <font color='#0000FF'><u>double</u></font> angle
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// make sure requires clause is not broken
</font>        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font> <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> ,
            "<font color='#CC0000'>\t point_transform_affine rotate_image()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid inputs were given to this function.</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t is_same_object(in_img, out_img):  </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font>
            <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>return</font> <font color='#BB00BB'>rotate_image</font><font face='Lucida Console'>(</font>in_img, out_img, angle, <font color='#BB00BB'>interpolate_quadratic</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>namespace</font> impl
    <b>{</b>
        <font color='#0000FF'>class</font> <b><a name='helper_resize_image'></a>helper_resize_image</b> 
        <b>{</b>
        <font color='#0000FF'>public</font>:
            <b><a name='helper_resize_image'></a>helper_resize_image</b><font face='Lucida Console'>(</font>
                <font color='#0000FF'><u>double</u></font> x_scale_,
                <font color='#0000FF'><u>double</u></font> y_scale_
            <font face='Lucida Console'>)</font>:
                x_scale<font face='Lucida Console'>(</font>x_scale_<font face='Lucida Console'>)</font>,
                y_scale<font face='Lucida Console'>(</font>y_scale_<font face='Lucida Console'>)</font>
            <b>{</b><b>}</b>

            dlib::vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font> <b><a name='operator'></a>operator</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>
                <font color='#0000FF'>const</font> dlib::vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> p
            <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
            <b>{</b>
                <font color='#0000FF'>return</font> dlib::vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>p.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>x_scale, p.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>y_scale<font face='Lucida Console'>)</font>;
            <b>}</b>

        <font color='#0000FF'>private</font>:
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> x_scale;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> y_scale;
        <b>}</b>;
    <b>}</b>

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type1,
        <font color='#0000FF'>typename</font> image_type2,
        <font color='#0000FF'>typename</font> interpolation_type
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='resize_image'></a>resize_image</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> image_type1<font color='#5555FF'>&amp;</font> in_img,
        image_type2<font color='#5555FF'>&amp;</font> out_img,
        <font color='#0000FF'>const</font> interpolation_type<font color='#5555FF'>&amp;</font> interp
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// make sure requires clause is not broken
</font>        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font> <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> ,
            "<font color='#CC0000'>\t void resize_image()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid inputs were given to this function.</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t is_same_object(in_img, out_img):  </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font>
            <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> x_scale <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>in_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font><font face='Lucida Console'>)</font>std::max<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>out_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>,<font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> y_scale <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>in_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font><font face='Lucida Console'>)</font>std::max<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>out_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>,<font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>transform_image</font><font face='Lucida Console'>(</font>in_img, out_img, interp, 
                        dlib::impl::<font color='#BB00BB'>helper_resize_image</font><font face='Lucida Console'>(</font>x_scale,y_scale<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> image_type<font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>struct</font> <b><a name='is_rgb_image'></a>is_rgb_image</b> <b>{</b> <font color='#0000FF'>const</font> <font color='#0000FF'>static</font> <font color='#0000FF'><u>bool</u></font> value <font color='#5555FF'>=</font> pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> image_type::type<font color='#5555FF'>&gt;</font>::rgb; <b>}</b>;
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> image_type<font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>struct</font> <b><a name='is_grayscale_image'></a>is_grayscale_image</b> <b>{</b> <font color='#0000FF'>const</font> <font color='#0000FF'>static</font> <font color='#0000FF'><u>bool</u></font> value <font color='#5555FF'>=</font> pixel_traits<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> image_type::type<font color='#5555FF'>&gt;</font>::grayscale; <b>}</b>;

    <font color='#009900'>// This is an optimized version of resize_image for the case where bilinear
</font>    <font color='#009900'>// interpolation is used.
</font>    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type1,
        <font color='#0000FF'>typename</font> image_type2
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>typename</font> disable_if_c<font color='#5555FF'>&lt;</font><font face='Lucida Console'>(</font>is_rgb_image<font color='#5555FF'>&lt;</font>image_type1<font color='#5555FF'>&gt;</font>::value<font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>is_rgb_image<font color='#5555FF'>&lt;</font>image_type2<font color='#5555FF'>&gt;</font>::value<font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> 
                          <font face='Lucida Console'>(</font>is_grayscale_image<font color='#5555FF'>&lt;</font>image_type1<font color='#5555FF'>&gt;</font>::value<font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>is_grayscale_image<font color='#5555FF'>&lt;</font>image_type2<font color='#5555FF'>&gt;</font>::value<font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font>::type 
    <b><a name='resize_image'></a>resize_image</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> image_type1<font color='#5555FF'>&amp;</font> in_img,
        image_type2<font color='#5555FF'>&amp;</font> out_img,
        interpolate_bilinear
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// make sure requires clause is not broken
</font>        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font> <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> ,
            "<font color='#CC0000'>\t void resize_image()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid inputs were given to this function.</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t is_same_object(in_img, out_img):  </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font>
            <font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>out_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> <font color='#979000'>1</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> out_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>assign_all_pixels</font><font face='Lucida Console'>(</font>out_img, <font color='#979000'>0</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font>;
        <b>}</b>


        <font color='#0000FF'>typedef</font> <font color='#0000FF'>typename</font> image_type1::type T;
        <font color='#0000FF'>typedef</font> <font color='#0000FF'>typename</font> image_type2::type U;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> x_scale <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>in_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font><font face='Lucida Console'>)</font>std::max<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>out_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>,<font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> y_scale <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>in_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font><font face='Lucida Console'>)</font>std::max<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>out_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>,<font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'><u>double</u></font> y <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>y_scale;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> r <font color='#5555FF'>=</font> <font color='#979000'>0</font>; r <font color='#5555FF'>&lt;</font> out_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>r<font face='Lucida Console'>)</font>
        <b>{</b>
            y <font color='#5555FF'>+</font><font color='#5555FF'>=</font> y_scale;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> top    <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>floor</font><font face='Lucida Console'>(</font>y<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> bottom <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>top<font color='#5555FF'>+</font><font color='#979000'>1</font>, in_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> tb_frac <font color='#5555FF'>=</font> y <font color='#5555FF'>-</font> top;
            <font color='#0000FF'><u>double</u></font> x <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>x_scale;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>pixel_traits<font color='#5555FF'>&lt;</font>U<font color='#5555FF'>&gt;</font>::rgb<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> c <font color='#5555FF'>=</font> <font color='#979000'>0</font>; c <font color='#5555FF'>&lt;</font> out_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>c<font face='Lucida Console'>)</font>
                <b>{</b>
                    x <font color='#5555FF'>+</font><font color='#5555FF'>=</font> x_scale;
                    <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> left   <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>floor</font><font face='Lucida Console'>(</font>x<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> right  <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>left<font color='#5555FF'>+</font><font color='#979000'>1</font>, in_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> lr_frac <font color='#5555FF'>=</font> x <font color='#5555FF'>-</font> left;

                    <font color='#0000FF'><u>double</u></font> tl <font color='#5555FF'>=</font> <font color='#979000'>0</font>, tr <font color='#5555FF'>=</font> <font color='#979000'>0</font>, bl <font color='#5555FF'>=</font> <font color='#979000'>0</font>, br <font color='#5555FF'>=</font> <font color='#979000'>0</font>;

                    <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>tl, in_img[top][left]<font face='Lucida Console'>)</font>;
                    <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>tr, in_img[top][right]<font face='Lucida Console'>)</font>;
                    <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>bl, in_img[bottom][left]<font face='Lucida Console'>)</font>;
                    <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>br, in_img[bottom][right]<font face='Lucida Console'>)</font>;

                    <font color='#0000FF'><u>double</u></font> temp <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#979000'>1</font><font color='#5555FF'>-</font>tb_frac<font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font color='#5555FF'>-</font>lr_frac<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>tl <font color='#5555FF'>+</font> lr_frac<font color='#5555FF'>*</font>tr<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> 
                        tb_frac<font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font color='#5555FF'>-</font>lr_frac<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>bl <font color='#5555FF'>+</font> lr_frac<font color='#5555FF'>*</font>br<font face='Lucida Console'>)</font>;

                    <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>out_img[r][c], temp<font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> c <font color='#5555FF'>=</font> <font color='#979000'>0</font>; c <font color='#5555FF'>&lt;</font> out_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>c<font face='Lucida Console'>)</font>
                <b>{</b>
                    x <font color='#5555FF'>+</font><font color='#5555FF'>=</font> x_scale;
                    <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> left   <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>floor</font><font face='Lucida Console'>(</font>x<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> right  <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>left<font color='#5555FF'>+</font><font color='#979000'>1</font>, in_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> lr_frac <font color='#5555FF'>=</font> x <font color='#5555FF'>-</font> left;

                    <font color='#0000FF'>const</font> T tl <font color='#5555FF'>=</font> in_img[top][left];
                    <font color='#0000FF'>const</font> T tr <font color='#5555FF'>=</font> in_img[top][right];
                    <font color='#0000FF'>const</font> T bl <font color='#5555FF'>=</font> in_img[bottom][left];
                    <font color='#0000FF'>const</font> T br <font color='#5555FF'>=</font> in_img[bottom][right];

                    T temp;
                    <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>temp, <font color='#979000'>0</font><font face='Lucida Console'>)</font>;
                    <font color='#BB00BB'>vector_to_pixel</font><font face='Lucida Console'>(</font>temp, 
                        <font face='Lucida Console'>(</font><font color='#979000'>1</font><font color='#5555FF'>-</font>tb_frac<font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font color='#5555FF'>-</font>lr_frac<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>pixel_to_vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>tl<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> lr_frac<font color='#5555FF'>*</font>pixel_to_vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>tr<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> 
                            tb_frac<font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font color='#5555FF'>-</font>lr_frac<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>pixel_to_vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>bl<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> lr_frac<font color='#5555FF'>*</font>pixel_to_vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>br<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>out_img[r][c], temp<font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>typename</font> enable_if<font color='#5555FF'>&lt;</font>is_grayscale_image<font color='#5555FF'>&lt;</font>image_type<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font>::type <b><a name='resize_image'></a>resize_image</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> image_type<font color='#5555FF'>&amp;</font> in_img,
        image_type<font color='#5555FF'>&amp;</font> out_img,
        interpolate_bilinear
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// make sure requires clause is not broken
</font>        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font> <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> ,
            "<font color='#CC0000'>\t void resize_image()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid inputs were given to this function.</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t is_same_object(in_img, out_img):  </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font>
            <font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>out_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> <font color='#979000'>1</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> out_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>assign_all_pixels</font><font face='Lucida Console'>(</font>out_img, <font color='#979000'>0</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font>;
        <b>}</b>

        <font color='#0000FF'>typedef</font> <font color='#0000FF'>typename</font> image_type::type T;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> x_scale <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>in_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font><font face='Lucida Console'>)</font>std::max<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>out_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>,<font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> y_scale <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>in_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font><font face='Lucida Console'>)</font>std::max<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>out_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>,<font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'><u>double</u></font> y <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>y_scale;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> r <font color='#5555FF'>=</font> <font color='#979000'>0</font>; r <font color='#5555FF'>&lt;</font> out_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>r<font face='Lucida Console'>)</font>
        <b>{</b>
            y <font color='#5555FF'>+</font><font color='#5555FF'>=</font> y_scale;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> top    <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>floor</font><font face='Lucida Console'>(</font>y<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> bottom <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>top<font color='#5555FF'>+</font><font color='#979000'>1</font>, in_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> tb_frac <font color='#5555FF'>=</font> y <font color='#5555FF'>-</font> top;
            <font color='#0000FF'><u>double</u></font> x <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>4</font><font color='#5555FF'>*</font>x_scale;

            <font color='#0000FF'>const</font> simd4f _tb_frac <font color='#5555FF'>=</font> tb_frac;
            <font color='#0000FF'>const</font> simd4f _inv_tb_frac <font color='#5555FF'>=</font> <font color='#979000'>1</font><font color='#5555FF'>-</font>tb_frac;
            <font color='#0000FF'>const</font> simd4f _x_scale <font color='#5555FF'>=</font> <font color='#979000'>4</font><font color='#5555FF'>*</font>x_scale;
            simd4f <font color='#BB00BB'>_x</font><font face='Lucida Console'>(</font>x, x<font color='#5555FF'>+</font>x_scale, x<font color='#5555FF'>+</font><font color='#979000'>2</font><font color='#5555FF'>*</font>x_scale, x<font color='#5555FF'>+</font><font color='#979000'>3</font><font color='#5555FF'>*</font>x_scale<font face='Lucida Console'>)</font>;
            <font color='#0000FF'><u>long</u></font> c <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>;; c<font color='#5555FF'>+</font><font color='#5555FF'>=</font><font color='#979000'>4</font><font face='Lucida Console'>)</font>
            <b>{</b>
                _x <font color='#5555FF'>+</font><font color='#5555FF'>=</font> _x_scale;
                simd4i left <font color='#5555FF'>=</font> <font color='#BB00BB'>simd4i</font><font face='Lucida Console'>(</font>_x<font face='Lucida Console'>)</font>;

                simd4f _lr_frac <font color='#5555FF'>=</font> _x<font color='#5555FF'>-</font>left;
                simd4f _inv_lr_frac <font color='#5555FF'>=</font> <font color='#979000'>1</font><font color='#5555FF'>-</font>_lr_frac; 
                simd4i right <font color='#5555FF'>=</font> left<font color='#5555FF'>+</font><font color='#979000'>1</font>;

                simd4f tlf <font color='#5555FF'>=</font> _inv_tb_frac<font color='#5555FF'>*</font>_inv_lr_frac;
                simd4f trf <font color='#5555FF'>=</font> _inv_tb_frac<font color='#5555FF'>*</font>_lr_frac;
                simd4f blf <font color='#5555FF'>=</font> _tb_frac<font color='#5555FF'>*</font>_inv_lr_frac;
                simd4f brf <font color='#5555FF'>=</font> _tb_frac<font color='#5555FF'>*</font>_lr_frac;

                int32 fleft[<font color='#979000'>4</font>];
                int32 fright[<font color='#979000'>4</font>];
                left.<font color='#BB00BB'>store</font><font face='Lucida Console'>(</font>fleft<font face='Lucida Console'>)</font>;
                right.<font color='#BB00BB'>store</font><font face='Lucida Console'>(</font>fright<font face='Lucida Console'>)</font>;

                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>fright[<font color='#979000'>3</font>] <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> in_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                    <font color='#0000FF'>break</font>;
                simd4f <font color='#BB00BB'>tl</font><font face='Lucida Console'>(</font>in_img[top][fleft[<font color='#979000'>0</font>]],     in_img[top][fleft[<font color='#979000'>1</font>]],     in_img[top][fleft[<font color='#979000'>2</font>]],     in_img[top][fleft[<font color='#979000'>3</font>]]<font face='Lucida Console'>)</font>;
                simd4f <font color='#BB00BB'>tr</font><font face='Lucida Console'>(</font>in_img[top][fright[<font color='#979000'>0</font>]],    in_img[top][fright[<font color='#979000'>1</font>]],    in_img[top][fright[<font color='#979000'>2</font>]],    in_img[top][fright[<font color='#979000'>3</font>]]<font face='Lucida Console'>)</font>;
                simd4f <font color='#BB00BB'>bl</font><font face='Lucida Console'>(</font>in_img[bottom][fleft[<font color='#979000'>0</font>]],  in_img[bottom][fleft[<font color='#979000'>1</font>]],  in_img[bottom][fleft[<font color='#979000'>2</font>]],  in_img[bottom][fleft[<font color='#979000'>3</font>]]<font face='Lucida Console'>)</font>;
                simd4f <font color='#BB00BB'>br</font><font face='Lucida Console'>(</font>in_img[bottom][fright[<font color='#979000'>0</font>]], in_img[bottom][fright[<font color='#979000'>1</font>]], in_img[bottom][fright[<font color='#979000'>2</font>]], in_img[bottom][fright[<font color='#979000'>3</font>]]<font face='Lucida Console'>)</font>;

                simd4i out <font color='#5555FF'>=</font> <font color='#BB00BB'>simd4i</font><font face='Lucida Console'>(</font>tlf<font color='#5555FF'>*</font>tl <font color='#5555FF'>+</font> trf<font color='#5555FF'>*</font>tr <font color='#5555FF'>+</font> blf<font color='#5555FF'>*</font>bl <font color='#5555FF'>+</font> brf<font color='#5555FF'>*</font>br<font face='Lucida Console'>)</font>;
                int32 fout[<font color='#979000'>4</font>];
                out.<font color='#BB00BB'>store</font><font face='Lucida Console'>(</font>fout<font face='Lucida Console'>)</font>;

                out_img[r][c]   <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font>T<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>fout[<font color='#979000'>0</font>]<font face='Lucida Console'>)</font>;
                out_img[r][c<font color='#5555FF'>+</font><font color='#979000'>1</font>] <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font>T<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>fout[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font>;
                out_img[r][c<font color='#5555FF'>+</font><font color='#979000'>2</font>] <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font>T<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>fout[<font color='#979000'>2</font>]<font face='Lucida Console'>)</font>;
                out_img[r][c<font color='#5555FF'>+</font><font color='#979000'>3</font>] <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font>T<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>fout[<font color='#979000'>3</font>]<font face='Lucida Console'>)</font>;
            <b>}</b>
            x <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>x_scale <font color='#5555FF'>+</font> c<font color='#5555FF'>*</font>x_scale;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>; c <font color='#5555FF'>&lt;</font> out_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>c<font face='Lucida Console'>)</font>
            <b>{</b>
                x <font color='#5555FF'>+</font><font color='#5555FF'>=</font> x_scale;
                <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> left   <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>floor</font><font face='Lucida Console'>(</font>x<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> right  <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>left<font color='#5555FF'>+</font><font color='#979000'>1</font>, in_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>const</font> <font color='#0000FF'><u>float</u></font> lr_frac <font color='#5555FF'>=</font> x <font color='#5555FF'>-</font> left;

                <font color='#0000FF'><u>float</u></font> tl <font color='#5555FF'>=</font> <font color='#979000'>0</font>, tr <font color='#5555FF'>=</font> <font color='#979000'>0</font>, bl <font color='#5555FF'>=</font> <font color='#979000'>0</font>, br <font color='#5555FF'>=</font> <font color='#979000'>0</font>;

                <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>tl, in_img[top][left]<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>tr, in_img[top][right]<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>bl, in_img[bottom][left]<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>br, in_img[bottom][right]<font face='Lucida Console'>)</font>;

                <font color='#0000FF'><u>float</u></font> temp <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#979000'>1</font><font color='#5555FF'>-</font>tb_frac<font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font color='#5555FF'>-</font>lr_frac<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>tl <font color='#5555FF'>+</font> lr_frac<font color='#5555FF'>*</font>tr<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> 
                    tb_frac<font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font color='#5555FF'>-</font>lr_frac<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>bl <font color='#5555FF'>+</font> lr_frac<font color='#5555FF'>*</font>br<font face='Lucida Console'>)</font>;

                <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>out_img[r][c], temp<font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>typename</font> enable_if<font color='#5555FF'>&lt;</font>is_rgb_image<font color='#5555FF'>&lt;</font>image_type<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font>::type <b><a name='resize_image'></a>resize_image</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> image_type<font color='#5555FF'>&amp;</font> in_img,
        image_type<font color='#5555FF'>&amp;</font> out_img,
        interpolate_bilinear
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// make sure requires clause is not broken
</font>        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font> <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> ,
            "<font color='#CC0000'>\t void resize_image()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid inputs were given to this function.</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t is_same_object(in_img, out_img):  </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font>
            <font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>out_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> <font color='#979000'>1</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> out_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>assign_all_pixels</font><font face='Lucida Console'>(</font>out_img, <font color='#979000'>0</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font>;
        <b>}</b>


        <font color='#0000FF'>typedef</font> <font color='#0000FF'>typename</font> image_type::type T;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> x_scale <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>in_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font><font face='Lucida Console'>)</font>std::max<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>out_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>,<font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> y_scale <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>in_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font><font face='Lucida Console'>)</font>std::max<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>out_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>,<font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'><u>double</u></font> y <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>y_scale;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> r <font color='#5555FF'>=</font> <font color='#979000'>0</font>; r <font color='#5555FF'>&lt;</font> out_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>r<font face='Lucida Console'>)</font>
        <b>{</b>
            y <font color='#5555FF'>+</font><font color='#5555FF'>=</font> y_scale;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> top    <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>floor</font><font face='Lucida Console'>(</font>y<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> bottom <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>top<font color='#5555FF'>+</font><font color='#979000'>1</font>, in_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> tb_frac <font color='#5555FF'>=</font> y <font color='#5555FF'>-</font> top;
            <font color='#0000FF'><u>double</u></font> x <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>4</font><font color='#5555FF'>*</font>x_scale;

            <font color='#0000FF'>const</font> simd4f _tb_frac <font color='#5555FF'>=</font> tb_frac;
            <font color='#0000FF'>const</font> simd4f _inv_tb_frac <font color='#5555FF'>=</font> <font color='#979000'>1</font><font color='#5555FF'>-</font>tb_frac;
            <font color='#0000FF'>const</font> simd4f _x_scale <font color='#5555FF'>=</font> <font color='#979000'>4</font><font color='#5555FF'>*</font>x_scale;
            simd4f <font color='#BB00BB'>_x</font><font face='Lucida Console'>(</font>x, x<font color='#5555FF'>+</font>x_scale, x<font color='#5555FF'>+</font><font color='#979000'>2</font><font color='#5555FF'>*</font>x_scale, x<font color='#5555FF'>+</font><font color='#979000'>3</font><font color='#5555FF'>*</font>x_scale<font face='Lucida Console'>)</font>;
            <font color='#0000FF'><u>long</u></font> c <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>;; c<font color='#5555FF'>+</font><font color='#5555FF'>=</font><font color='#979000'>4</font><font face='Lucida Console'>)</font>
            <b>{</b>
                _x <font color='#5555FF'>+</font><font color='#5555FF'>=</font> _x_scale;
                simd4i left <font color='#5555FF'>=</font> <font color='#BB00BB'>simd4i</font><font face='Lucida Console'>(</font>_x<font face='Lucida Console'>)</font>;
                simd4f lr_frac <font color='#5555FF'>=</font> _x<font color='#5555FF'>-</font>left;
                simd4f _inv_lr_frac <font color='#5555FF'>=</font> <font color='#979000'>1</font><font color='#5555FF'>-</font>lr_frac; 
                simd4i right <font color='#5555FF'>=</font> left<font color='#5555FF'>+</font><font color='#979000'>1</font>;

                simd4f tlf <font color='#5555FF'>=</font> _inv_tb_frac<font color='#5555FF'>*</font>_inv_lr_frac;
                simd4f trf <font color='#5555FF'>=</font> _inv_tb_frac<font color='#5555FF'>*</font>lr_frac;
                simd4f blf <font color='#5555FF'>=</font> _tb_frac<font color='#5555FF'>*</font>_inv_lr_frac;
                simd4f brf <font color='#5555FF'>=</font> _tb_frac<font color='#5555FF'>*</font>lr_frac;

                int32 fleft[<font color='#979000'>4</font>];
                int32 fright[<font color='#979000'>4</font>];
                left.<font color='#BB00BB'>store</font><font face='Lucida Console'>(</font>fleft<font face='Lucida Console'>)</font>;
                right.<font color='#BB00BB'>store</font><font face='Lucida Console'>(</font>fright<font face='Lucida Console'>)</font>;

                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>fright[<font color='#979000'>3</font>] <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> in_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                    <font color='#0000FF'>break</font>;
                simd4f <font color='#BB00BB'>tl</font><font face='Lucida Console'>(</font>in_img[top][fleft[<font color='#979000'>0</font>]].red,     in_img[top][fleft[<font color='#979000'>1</font>]].red,     in_img[top][fleft[<font color='#979000'>2</font>]].red,     in_img[top][fleft[<font color='#979000'>3</font>]].red<font face='Lucida Console'>)</font>;
                simd4f <font color='#BB00BB'>tr</font><font face='Lucida Console'>(</font>in_img[top][fright[<font color='#979000'>0</font>]].red,    in_img[top][fright[<font color='#979000'>1</font>]].red,    in_img[top][fright[<font color='#979000'>2</font>]].red,    in_img[top][fright[<font color='#979000'>3</font>]].red<font face='Lucida Console'>)</font>;
                simd4f <font color='#BB00BB'>bl</font><font face='Lucida Console'>(</font>in_img[bottom][fleft[<font color='#979000'>0</font>]].red,  in_img[bottom][fleft[<font color='#979000'>1</font>]].red,  in_img[bottom][fleft[<font color='#979000'>2</font>]].red,  in_img[bottom][fleft[<font color='#979000'>3</font>]].red<font face='Lucida Console'>)</font>;
                simd4f <font color='#BB00BB'>br</font><font face='Lucida Console'>(</font>in_img[bottom][fright[<font color='#979000'>0</font>]].red, in_img[bottom][fright[<font color='#979000'>1</font>]].red, in_img[bottom][fright[<font color='#979000'>2</font>]].red, in_img[bottom][fright[<font color='#979000'>3</font>]].red<font face='Lucida Console'>)</font>;

                simd4i out <font color='#5555FF'>=</font> <font color='#BB00BB'>simd4i</font><font face='Lucida Console'>(</font>tlf<font color='#5555FF'>*</font>tl <font color='#5555FF'>+</font> trf<font color='#5555FF'>*</font>tr <font color='#5555FF'>+</font> blf<font color='#5555FF'>*</font>bl <font color='#5555FF'>+</font> brf<font color='#5555FF'>*</font>br<font face='Lucida Console'>)</font>;
                int32 fout[<font color='#979000'>4</font>];
                out.<font color='#BB00BB'>store</font><font face='Lucida Console'>(</font>fout<font face='Lucida Console'>)</font>;

                out_img[r][c].red   <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>char</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>fout[<font color='#979000'>0</font>]<font face='Lucida Console'>)</font>;
                out_img[r][c<font color='#5555FF'>+</font><font color='#979000'>1</font>].red <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>char</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>fout[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font>;
                out_img[r][c<font color='#5555FF'>+</font><font color='#979000'>2</font>].red <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>char</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>fout[<font color='#979000'>2</font>]<font face='Lucida Console'>)</font>;
                out_img[r][c<font color='#5555FF'>+</font><font color='#979000'>3</font>].red <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>char</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>fout[<font color='#979000'>3</font>]<font face='Lucida Console'>)</font>;


                tl <font color='#5555FF'>=</font> <font color='#BB00BB'>simd4f</font><font face='Lucida Console'>(</font>in_img[top][fleft[<font color='#979000'>0</font>]].green,    in_img[top][fleft[<font color='#979000'>1</font>]].green,    in_img[top][fleft[<font color='#979000'>2</font>]].green,    in_img[top][fleft[<font color='#979000'>3</font>]].green<font face='Lucida Console'>)</font>;
                tr <font color='#5555FF'>=</font> <font color='#BB00BB'>simd4f</font><font face='Lucida Console'>(</font>in_img[top][fright[<font color='#979000'>0</font>]].green,   in_img[top][fright[<font color='#979000'>1</font>]].green,   in_img[top][fright[<font color='#979000'>2</font>]].green,   in_img[top][fright[<font color='#979000'>3</font>]].green<font face='Lucida Console'>)</font>;
                bl <font color='#5555FF'>=</font> <font color='#BB00BB'>simd4f</font><font face='Lucida Console'>(</font>in_img[bottom][fleft[<font color='#979000'>0</font>]].green, in_img[bottom][fleft[<font color='#979000'>1</font>]].green, in_img[bottom][fleft[<font color='#979000'>2</font>]].green, in_img[bottom][fleft[<font color='#979000'>3</font>]].green<font face='Lucida Console'>)</font>;
                br <font color='#5555FF'>=</font> <font color='#BB00BB'>simd4f</font><font face='Lucida Console'>(</font>in_img[bottom][fright[<font color='#979000'>0</font>]].green, in_img[bottom][fright[<font color='#979000'>1</font>]].green, in_img[bottom][fright[<font color='#979000'>2</font>]].green, in_img[bottom][fright[<font color='#979000'>3</font>]].green<font face='Lucida Console'>)</font>;
                out <font color='#5555FF'>=</font> <font color='#BB00BB'>simd4i</font><font face='Lucida Console'>(</font>tlf<font color='#5555FF'>*</font>tl <font color='#5555FF'>+</font> trf<font color='#5555FF'>*</font>tr <font color='#5555FF'>+</font> blf<font color='#5555FF'>*</font>bl <font color='#5555FF'>+</font> brf<font color='#5555FF'>*</font>br<font face='Lucida Console'>)</font>;
                out.<font color='#BB00BB'>store</font><font face='Lucida Console'>(</font>fout<font face='Lucida Console'>)</font>;
                out_img[r][c].green   <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>char</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>fout[<font color='#979000'>0</font>]<font face='Lucida Console'>)</font>;
                out_img[r][c<font color='#5555FF'>+</font><font color='#979000'>1</font>].green <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>char</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>fout[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font>;
                out_img[r][c<font color='#5555FF'>+</font><font color='#979000'>2</font>].green <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>char</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>fout[<font color='#979000'>2</font>]<font face='Lucida Console'>)</font>;
                out_img[r][c<font color='#5555FF'>+</font><font color='#979000'>3</font>].green <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>char</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>fout[<font color='#979000'>3</font>]<font face='Lucida Console'>)</font>;


                tl <font color='#5555FF'>=</font> <font color='#BB00BB'>simd4f</font><font face='Lucida Console'>(</font>in_img[top][fleft[<font color='#979000'>0</font>]].blue,     in_img[top][fleft[<font color='#979000'>1</font>]].blue,     in_img[top][fleft[<font color='#979000'>2</font>]].blue,     in_img[top][fleft[<font color='#979000'>3</font>]].blue<font face='Lucida Console'>)</font>;
                tr <font color='#5555FF'>=</font> <font color='#BB00BB'>simd4f</font><font face='Lucida Console'>(</font>in_img[top][fright[<font color='#979000'>0</font>]].blue,    in_img[top][fright[<font color='#979000'>1</font>]].blue,    in_img[top][fright[<font color='#979000'>2</font>]].blue,    in_img[top][fright[<font color='#979000'>3</font>]].blue<font face='Lucida Console'>)</font>;
                bl <font color='#5555FF'>=</font> <font color='#BB00BB'>simd4f</font><font face='Lucida Console'>(</font>in_img[bottom][fleft[<font color='#979000'>0</font>]].blue,  in_img[bottom][fleft[<font color='#979000'>1</font>]].blue,  in_img[bottom][fleft[<font color='#979000'>2</font>]].blue,  in_img[bottom][fleft[<font color='#979000'>3</font>]].blue<font face='Lucida Console'>)</font>;
                br <font color='#5555FF'>=</font> <font color='#BB00BB'>simd4f</font><font face='Lucida Console'>(</font>in_img[bottom][fright[<font color='#979000'>0</font>]].blue, in_img[bottom][fright[<font color='#979000'>1</font>]].blue, in_img[bottom][fright[<font color='#979000'>2</font>]].blue, in_img[bottom][fright[<font color='#979000'>3</font>]].blue<font face='Lucida Console'>)</font>;
                out <font color='#5555FF'>=</font> <font color='#BB00BB'>simd4i</font><font face='Lucida Console'>(</font>tlf<font color='#5555FF'>*</font>tl <font color='#5555FF'>+</font> trf<font color='#5555FF'>*</font>tr <font color='#5555FF'>+</font> blf<font color='#5555FF'>*</font>bl <font color='#5555FF'>+</font> brf<font color='#5555FF'>*</font>br<font face='Lucida Console'>)</font>;
                out.<font color='#BB00BB'>store</font><font face='Lucida Console'>(</font>fout<font face='Lucida Console'>)</font>;
                out_img[r][c].blue   <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>char</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>fout[<font color='#979000'>0</font>]<font face='Lucida Console'>)</font>;
                out_img[r][c<font color='#5555FF'>+</font><font color='#979000'>1</font>].blue <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>char</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>fout[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font>;
                out_img[r][c<font color='#5555FF'>+</font><font color='#979000'>2</font>].blue <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>char</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>fout[<font color='#979000'>2</font>]<font face='Lucida Console'>)</font>;
                out_img[r][c<font color='#5555FF'>+</font><font color='#979000'>3</font>].blue <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>char</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>fout[<font color='#979000'>3</font>]<font face='Lucida Console'>)</font>;
            <b>}</b>
            x <font color='#5555FF'>=</font> <font color='#5555FF'>-</font>x_scale <font color='#5555FF'>+</font> c<font color='#5555FF'>*</font>x_scale;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>; c <font color='#5555FF'>&lt;</font> out_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>c<font face='Lucida Console'>)</font>
            <b>{</b>
                x <font color='#5555FF'>+</font><font color='#5555FF'>=</font> x_scale;
                <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> left   <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>floor</font><font face='Lucida Console'>(</font>x<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> right  <font color='#5555FF'>=</font> std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>left<font color='#5555FF'>+</font><font color='#979000'>1</font>, in_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> lr_frac <font color='#5555FF'>=</font> x <font color='#5555FF'>-</font> left;

                <font color='#0000FF'>const</font> T tl <font color='#5555FF'>=</font> in_img[top][left];
                <font color='#0000FF'>const</font> T tr <font color='#5555FF'>=</font> in_img[top][right];
                <font color='#0000FF'>const</font> T bl <font color='#5555FF'>=</font> in_img[bottom][left];
                <font color='#0000FF'>const</font> T br <font color='#5555FF'>=</font> in_img[bottom][right];

                T temp;
                <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>temp, <font color='#979000'>0</font><font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>vector_to_pixel</font><font face='Lucida Console'>(</font>temp, 
                    <font face='Lucida Console'>(</font><font color='#979000'>1</font><font color='#5555FF'>-</font>tb_frac<font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font color='#5555FF'>-</font>lr_frac<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>pixel_to_vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>tl<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> lr_frac<font color='#5555FF'>*</font>pixel_to_vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>tr<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> 
                    tb_frac<font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font color='#5555FF'>-</font>lr_frac<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>pixel_to_vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>bl<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> lr_frac<font color='#5555FF'>*</font>pixel_to_vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>br<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>out_img[r][c], temp<font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type1,
        <font color='#0000FF'>typename</font> image_type2
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='resize_image'></a>resize_image</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> image_type1<font color='#5555FF'>&amp;</font> in_img,
        image_type2<font color='#5555FF'>&amp;</font> out_img
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// make sure requires clause is not broken
</font>        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font> <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> ,
            "<font color='#CC0000'>\t void resize_image()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid inputs were given to this function.</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t is_same_object(in_img, out_img):  </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font>
            <font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>resize_image</font><font face='Lucida Console'>(</font>in_img, out_img, <font color='#BB00BB'>interpolate_bilinear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type1,
        <font color='#0000FF'>typename</font> image_type2
        <font color='#5555FF'>&gt;</font>
    point_transform_affine <b><a name='flip_image_left_right'></a>flip_image_left_right</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> image_type1<font color='#5555FF'>&amp;</font> in_img,
        image_type2<font color='#5555FF'>&amp;</font> out_img
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// make sure requires clause is not broken
</font>        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font> <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> ,
            "<font color='#CC0000'>\t void flip_image_left_right()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid inputs were given to this function.</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t is_same_object(in_img, out_img):  </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font>
            <font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>assign_image</font><font face='Lucida Console'>(</font>out_img, <font color='#BB00BB'>fliplr</font><font face='Lucida Console'>(</font><font color='#BB00BB'>mat</font><font face='Lucida Console'>(</font>in_img<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        std::vector<font color='#5555FF'>&lt;</font>dlib::vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font> from, to;
        rectangle r <font color='#5555FF'>=</font> <font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font>in_img<font face='Lucida Console'>)</font>;
        from.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>r.<font color='#BB00BB'>tl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; to.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>r.<font color='#BB00BB'>tr_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        from.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>r.<font color='#BB00BB'>bl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; to.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>r.<font color='#BB00BB'>br_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        from.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>r.<font color='#BB00BB'>tr_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; to.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>r.<font color='#BB00BB'>tl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        from.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>r.<font color='#BB00BB'>br_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; to.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>r.<font color='#BB00BB'>bl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> <font color='#BB00BB'>find_affine_transform</font><font face='Lucida Console'>(</font>from,to<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type1,
        <font color='#0000FF'>typename</font> image_type2
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='flip_image_up_down'></a>flip_image_up_down</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> image_type1<font color='#5555FF'>&amp;</font> in_img,
        image_type2<font color='#5555FF'>&amp;</font> out_img
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// make sure requires clause is not broken
</font>        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font> <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> ,
            "<font color='#CC0000'>\t void flip_image_up_down()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid inputs were given to this function.</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t is_same_object(in_img, out_img):  </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font>
            <font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>assign_image</font><font face='Lucida Console'>(</font>out_img, <font color='#BB00BB'>flipud</font><font face='Lucida Console'>(</font><font color='#BB00BB'>mat</font><font face='Lucida Console'>(</font>in_img<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>namespace</font> impl
    <b>{</b>
        <font color='#0000FF'>inline</font> rectangle <b><a name='flip_rect_left_right'></a>flip_rect_left_right</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect,
            <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> window 
        <font face='Lucida Console'>)</font>
        <b>{</b>
            rectangle temp;
            temp.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            temp.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> left_dist <font color='#5555FF'>=</font> rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>window.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            temp.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> window.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>left_dist; 
            temp.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>  <font color='#5555FF'>=</font> temp.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font>; 
            <font color='#0000FF'>return</font> temp;
        <b>}</b>

        <font color='#0000FF'>inline</font> rectangle <b><a name='tform_object'></a>tform_object</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> point_transform_affine<font color='#5555FF'>&amp;</font> tran,
            <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>return</font> <font color='#BB00BB'>centered_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>tran</font><font face='Lucida Console'>(</font><font color='#BB00BB'>center</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>, rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'>inline</font> full_object_detection <b><a name='tform_object'></a>tform_object</b><font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> point_transform_affine<font color='#5555FF'>&amp;</font> tran,
            <font color='#0000FF'>const</font> full_object_detection<font color='#5555FF'>&amp;</font> obj
        <font face='Lucida Console'>)</font>
        <b>{</b>
            std::vector<font color='#5555FF'>&lt;</font>point<font color='#5555FF'>&gt;</font> parts; 
            parts.<font color='#BB00BB'>reserve</font><font face='Lucida Console'>(</font>obj.<font color='#BB00BB'>num_parts</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> obj.<font color='#BB00BB'>num_parts</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
            <b>{</b>
                parts.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font><font color='#BB00BB'>tran</font><font face='Lucida Console'>(</font>obj.<font color='#BB00BB'>part</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <b>}</b>
            <font color='#0000FF'>return</font> <font color='#BB00BB'>full_object_detection</font><font face='Lucida Console'>(</font><font color='#BB00BB'>tform_object</font><font face='Lucida Console'>(</font>tran,obj.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>, parts<font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type,
        <font color='#0000FF'>typename</font> T
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='add_image_left_right_flips'></a>add_image_left_right_flips</b> <font face='Lucida Console'>(</font>
        dlib::array<font color='#5555FF'>&lt;</font>image_type<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> images,
        std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>T<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> objects
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// make sure requires clause is not broken
</font>        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font> images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> objects.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
            "<font color='#CC0000'>\t void add_image_left_right_flips()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid inputs were given to this function.</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t images.size():  </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t objects.size(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> objects.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
            <font face='Lucida Console'>)</font>;

        image_type temp;
        std::vector<font color='#5555FF'>&lt;</font>T<font color='#5555FF'>&gt;</font> rects;

        <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> num <font color='#5555FF'>=</font> images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> j <font color='#5555FF'>=</font> <font color='#979000'>0</font>; j <font color='#5555FF'>&lt;</font> num; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>const</font> point_transform_affine tran <font color='#5555FF'>=</font> <font color='#BB00BB'>flip_image_left_right</font><font face='Lucida Console'>(</font>images[j], temp<font face='Lucida Console'>)</font>;

            rects.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> objects[j].<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
                rects.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>impl::<font color='#BB00BB'>tform_object</font><font face='Lucida Console'>(</font>tran, objects[j][i]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

            images.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>;
            objects.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>rects<font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type,
        <font color='#0000FF'>typename</font> T,
        <font color='#0000FF'>typename</font> U
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='add_image_left_right_flips'></a>add_image_left_right_flips</b> <font face='Lucida Console'>(</font>
        dlib::array<font color='#5555FF'>&lt;</font>image_type<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> images,
        std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>T<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> objects,
        std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>U<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> objects2
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// make sure requires clause is not broken
</font>        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font> images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> objects.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                     images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> objects2.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
            "<font color='#CC0000'>\t void add_image_left_right_flips()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid inputs were given to this function.</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t images.size():   </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t objects.size():  </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> objects.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t objects2.size(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> objects2.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
            <font face='Lucida Console'>)</font>;

        image_type temp;
        std::vector<font color='#5555FF'>&lt;</font>T<font color='#5555FF'>&gt;</font> rects;
        std::vector<font color='#5555FF'>&lt;</font>U<font color='#5555FF'>&gt;</font> rects2;

        <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> num <font color='#5555FF'>=</font> images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> j <font color='#5555FF'>=</font> <font color='#979000'>0</font>; j <font color='#5555FF'>&lt;</font> num; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>const</font> point_transform_affine tran <font color='#5555FF'>=</font> <font color='#BB00BB'>flip_image_left_right</font><font face='Lucida Console'>(</font>images[j], temp<font face='Lucida Console'>)</font>;
            images.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>;

            rects.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> objects[j].<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
                rects.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>impl::<font color='#BB00BB'>tform_object</font><font face='Lucida Console'>(</font>tran, objects[j][i]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            objects.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>rects<font face='Lucida Console'>)</font>;

            rects2.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> objects2[j].<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
                rects2.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>impl::<font color='#BB00BB'>tform_object</font><font face='Lucida Console'>(</font>tran, objects2[j][i]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            objects2.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>rects2<font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> image_type<font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='flip_image_dataset_left_right'></a>flip_image_dataset_left_right</b> <font face='Lucida Console'>(</font>
        dlib::array<font color='#5555FF'>&lt;</font>image_type<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> images, 
        std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>rectangle<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> objects
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// make sure requires clause is not broken
</font>        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font> images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> objects.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
            "<font color='#CC0000'>\t void flip_image_dataset_left_right()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid inputs were given to this function.</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t images.size():   </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t objects.size():  </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> objects.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
            <font face='Lucida Console'>)</font>;

        image_type temp;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>flip_image_left_right</font><font face='Lucida Console'>(</font>images[i], temp<font face='Lucida Console'>)</font>; 
            temp.<font color='#BB00BB'>swap</font><font face='Lucida Console'>(</font>images[i]<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> j <font color='#5555FF'>=</font> <font color='#979000'>0</font>; j <font color='#5555FF'>&lt;</font> objects[i].<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font>
            <b>{</b>
                objects[i][j] <font color='#5555FF'>=</font> impl::<font color='#BB00BB'>flip_rect_left_right</font><font face='Lucida Console'>(</font>objects[i][j], <font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font>images[i]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> image_type<font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='flip_image_dataset_left_right'></a>flip_image_dataset_left_right</b> <font face='Lucida Console'>(</font>
        dlib::array<font color='#5555FF'>&lt;</font>image_type<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> images, 
        std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>rectangle<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> objects,
        std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>rectangle<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> objects2
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// make sure requires clause is not broken
</font>        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font> images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> objects.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                     images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> objects2.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
            "<font color='#CC0000'>\t void flip_image_dataset_left_right()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid inputs were given to this function.</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t images.size():   </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t objects.size():  </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> objects.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t objects2.size(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> objects2.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
            <font face='Lucida Console'>)</font>;

        image_type temp;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>flip_image_left_right</font><font face='Lucida Console'>(</font>images[i], temp<font face='Lucida Console'>)</font>; 
            temp.<font color='#BB00BB'>swap</font><font face='Lucida Console'>(</font>images[i]<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> j <font color='#5555FF'>=</font> <font color='#979000'>0</font>; j <font color='#5555FF'>&lt;</font> objects[i].<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font>
            <b>{</b>
                objects[i][j] <font color='#5555FF'>=</font> impl::<font color='#BB00BB'>flip_rect_left_right</font><font face='Lucida Console'>(</font>objects[i][j], <font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font>images[i]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <b>}</b>
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> j <font color='#5555FF'>=</font> <font color='#979000'>0</font>; j <font color='#5555FF'>&lt;</font> objects2[i].<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font>
            <b>{</b>
                objects2[i][j] <font color='#5555FF'>=</font> impl::<font color='#BB00BB'>flip_rect_left_right</font><font face='Lucida Console'>(</font>objects2[i][j], <font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font>images[i]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> pyramid_type,
        <font color='#0000FF'>typename</font> image_type
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='upsample_image_dataset'></a>upsample_image_dataset</b> <font face='Lucida Console'>(</font>
        dlib::array<font color='#5555FF'>&lt;</font>image_type<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> images,
        std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>rectangle<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> objects
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// make sure requires clause is not broken
</font>        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font> images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> objects.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
            "<font color='#CC0000'>\t void upsample_image_dataset()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid inputs were given to this function.</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t images.size():   </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t objects.size():  </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> objects.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
            <font face='Lucida Console'>)</font>;

        image_type temp;
        pyramid_type pyr;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>pyramid_up</font><font face='Lucida Console'>(</font>images[i], temp, pyr<font face='Lucida Console'>)</font>;
            temp.<font color='#BB00BB'>swap</font><font face='Lucida Console'>(</font>images[i]<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> j <font color='#5555FF'>=</font> <font color='#979000'>0</font>; j <font color='#5555FF'>&lt;</font> objects[i].<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font>
            <b>{</b>
                objects[i][j] <font color='#5555FF'>=</font> pyr.<font color='#BB00BB'>rect_up</font><font face='Lucida Console'>(</font>objects[i][j]<font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>
    <b>}</b>

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> pyramid_type,
        <font color='#0000FF'>typename</font> image_type
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='upsample_image_dataset'></a>upsample_image_dataset</b> <font face='Lucida Console'>(</font>
        dlib::array<font color='#5555FF'>&lt;</font>image_type<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> images,
        std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>rectangle<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> objects,
        std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>rectangle<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> objects2 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// make sure requires clause is not broken
</font>        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font> images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> objects.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                     images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> objects2.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
            "<font color='#CC0000'>\t void upsample_image_dataset()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid inputs were given to this function.</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t images.size():   </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t objects.size():  </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> objects.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t objects2.size(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> objects2.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
            <font face='Lucida Console'>)</font>;

        image_type temp;
        pyramid_type pyr;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>pyramid_up</font><font face='Lucida Console'>(</font>images[i], temp, pyr<font face='Lucida Console'>)</font>;
            temp.<font color='#BB00BB'>swap</font><font face='Lucida Console'>(</font>images[i]<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> j <font color='#5555FF'>=</font> <font color='#979000'>0</font>; j <font color='#5555FF'>&lt;</font> objects[i].<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font>
            <b>{</b>
                objects[i][j] <font color='#5555FF'>=</font> pyr.<font color='#BB00BB'>rect_up</font><font face='Lucida Console'>(</font>objects[i][j]<font face='Lucida Console'>)</font>;
            <b>}</b>
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> j <font color='#5555FF'>=</font> <font color='#979000'>0</font>; j <font color='#5555FF'>&lt;</font> objects2[i].<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font>
            <b>{</b>
                objects2[i][j] <font color='#5555FF'>=</font> pyr.<font color='#BB00BB'>rect_up</font><font face='Lucida Console'>(</font>objects2[i][j]<font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> image_type<font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='rotate_image_dataset'></a>rotate_image_dataset</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>double</u></font> angle,
        dlib::array<font color='#5555FF'>&lt;</font>image_type<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> images,
        std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>rectangle<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> objects
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// make sure requires clause is not broken
</font>        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font> images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> objects.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
            "<font color='#CC0000'>\t void rotate_image_dataset()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid inputs were given to this function.</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t images.size():   </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t objects.size():  </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> objects.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
            <font face='Lucida Console'>)</font>;

        image_type temp;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>const</font> point_transform_affine tran <font color='#5555FF'>=</font> <font color='#BB00BB'>rotate_image</font><font face='Lucida Console'>(</font>images[i], temp, angle<font face='Lucida Console'>)</font>;
            temp.<font color='#BB00BB'>swap</font><font face='Lucida Console'>(</font>images[i]<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> j <font color='#5555FF'>=</font> <font color='#979000'>0</font>; j <font color='#5555FF'>&lt;</font> objects[i].<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>const</font> rectangle rect <font color='#5555FF'>=</font> objects[i][j];
                objects[i][j] <font color='#5555FF'>=</font> <font color='#BB00BB'>centered_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>tran</font><font face='Lucida Console'>(</font><font color='#BB00BB'>center</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>, rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>
    <b>}</b>

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> image_type<font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='rotate_image_dataset'></a>rotate_image_dataset</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>double</u></font> angle,
        dlib::array<font color='#5555FF'>&lt;</font>image_type<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> images,
        std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>rectangle<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> objects,
        std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>rectangle<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> objects2
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// make sure requires clause is not broken
</font>        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font> images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> objects.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                     images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> objects2.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
            "<font color='#CC0000'>\t void rotate_image_dataset()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid inputs were given to this function.</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t images.size():   </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t objects.size():  </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> objects.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t objects2.size(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> objects2.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
            <font face='Lucida Console'>)</font>;

        image_type temp;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>const</font> point_transform_affine tran <font color='#5555FF'>=</font> <font color='#BB00BB'>rotate_image</font><font face='Lucida Console'>(</font>images[i], temp, angle<font face='Lucida Console'>)</font>;
            temp.<font color='#BB00BB'>swap</font><font face='Lucida Console'>(</font>images[i]<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> j <font color='#5555FF'>=</font> <font color='#979000'>0</font>; j <font color='#5555FF'>&lt;</font> objects[i].<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>const</font> rectangle rect <font color='#5555FF'>=</font> objects[i][j];
                objects[i][j] <font color='#5555FF'>=</font> <font color='#BB00BB'>centered_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>tran</font><font face='Lucida Console'>(</font><font color='#BB00BB'>center</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>, rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <b>}</b>
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> j <font color='#5555FF'>=</font> <font color='#979000'>0</font>; j <font color='#5555FF'>&lt;</font> objects2[i].<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>const</font> rectangle rect <font color='#5555FF'>=</font> objects2[i][j];
                objects2[i][j] <font color='#5555FF'>=</font> <font color='#BB00BB'>centered_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>tran</font><font face='Lucida Console'>(</font><font color='#BB00BB'>center</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>, rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type, 
        <font color='#0000FF'>typename</font> EXP, 
        <font color='#0000FF'>typename</font> T, 
        <font color='#0000FF'>typename</font> U
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='add_image_rotations'></a>add_image_rotations</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> matrix_exp<font color='#5555FF'>&lt;</font>EXP<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> angles,
        dlib::array<font color='#5555FF'>&lt;</font>image_type<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> images,
        std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>T<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> objects,
        std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>U<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> objects2
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// make sure requires clause is not broken
</font>        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font> <font color='#BB00BB'>is_vector</font><font face='Lucida Console'>(</font>angles<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> angles.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> 
                     images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> objects.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                     images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> objects2.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
            "<font color='#CC0000'>\t void add_image_rotations()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid inputs were given to this function.</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t is_vector(angles): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>is_vector</font><font face='Lucida Console'>(</font>angles<font face='Lucida Console'>)</font> 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t angles.size():     </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> angles.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t images.size():     </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t objects.size():    </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> objects.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t objects2.size():   </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> objects2.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
            <font face='Lucida Console'>)</font>;

        dlib::array<font color='#5555FF'>&lt;</font>image_type<font color='#5555FF'>&gt;</font> new_images;
        std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>T<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font> new_objects;
        std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>U<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font> new_objects2;

        <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> impl; 

        std::vector<font color='#5555FF'>&lt;</font>T<font color='#5555FF'>&gt;</font> objtemp;
        std::vector<font color='#5555FF'>&lt;</font>U<font color='#5555FF'>&gt;</font> objtemp2;
        image_type temp;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> angles.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> j <font color='#5555FF'>=</font> <font color='#979000'>0</font>; j <font color='#5555FF'>&lt;</font> images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>const</font> point_transform_affine tran <font color='#5555FF'>=</font> <font color='#BB00BB'>rotate_image</font><font face='Lucida Console'>(</font>images[j], temp, <font color='#BB00BB'>angles</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                new_images.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>;

                objtemp.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> k <font color='#5555FF'>=</font> <font color='#979000'>0</font>; k <font color='#5555FF'>&lt;</font> objects[j].<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font>
                    objtemp.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font><font color='#BB00BB'>tform_object</font><font face='Lucida Console'>(</font>tran, objects[j][k]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                new_objects.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>objtemp<font face='Lucida Console'>)</font>;

                objtemp2.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> k <font color='#5555FF'>=</font> <font color='#979000'>0</font>; k <font color='#5555FF'>&lt;</font> objects2[j].<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font>
                    objtemp2.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font><font color='#BB00BB'>tform_object</font><font face='Lucida Console'>(</font>tran, objects2[j][k]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                new_objects2.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>objtemp2<font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>

        new_images.<font color='#BB00BB'>swap</font><font face='Lucida Console'>(</font>images<font face='Lucida Console'>)</font>;
        new_objects.<font color='#BB00BB'>swap</font><font face='Lucida Console'>(</font>objects<font face='Lucida Console'>)</font>;
        new_objects2.<font color='#BB00BB'>swap</font><font face='Lucida Console'>(</font>objects2<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type, 
        <font color='#0000FF'>typename</font> EXP,
        <font color='#0000FF'>typename</font> T
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='add_image_rotations'></a>add_image_rotations</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> matrix_exp<font color='#5555FF'>&lt;</font>EXP<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> angles,
        dlib::array<font color='#5555FF'>&lt;</font>image_type<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> images,
        std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>T<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> objects
    <font face='Lucida Console'>)</font>
    <b>{</b>
        std::vector<font color='#5555FF'>&lt;</font>std::vector<font color='#5555FF'>&lt;</font>T<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font> <font color='#BB00BB'>objects2</font><font face='Lucida Console'>(</font>objects.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>add_image_rotations</font><font face='Lucida Console'>(</font>angles, images, objects, objects2<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type1,
        <font color='#0000FF'>typename</font> image_type2,
        <font color='#0000FF'>typename</font> pyramid_type,
        <font color='#0000FF'>typename</font> interpolation_type
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='pyramid_up'></a>pyramid_up</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> image_type1<font color='#5555FF'>&amp;</font> in_img,
        image_type2<font color='#5555FF'>&amp;</font> out_img,
        <font color='#0000FF'>const</font> pyramid_type<font color='#5555FF'>&amp;</font> pyr,
        <font color='#0000FF'>const</font> interpolation_type<font color='#5555FF'>&amp;</font> interp
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// make sure requires clause is not broken
</font>        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font> <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> ,
            "<font color='#CC0000'>\t void pyramid_up()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid inputs were given to this function.</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t is_same_object(in_img, out_img):  </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font>
            <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>in_img.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
        <b>{</b>
            out_img.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font>;
        <b>}</b>

        rectangle rect <font color='#5555FF'>=</font> <font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font>in_img<font face='Lucida Console'>)</font>;
        rectangle uprect <font color='#5555FF'>=</font> pyr.<font color='#BB00BB'>rect_up</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>uprect.<font color='#BB00BB'>is_empty</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            out_img.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font>;
        <b>}</b>
        out_img.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>uprect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font>, uprect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>resize_image</font><font face='Lucida Console'>(</font>in_img, out_img, interp<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type1,
        <font color='#0000FF'>typename</font> image_type2,
        <font color='#0000FF'>typename</font> pyramid_type
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='pyramid_up'></a>pyramid_up</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> image_type1<font color='#5555FF'>&amp;</font> in_img,
        image_type2<font color='#5555FF'>&amp;</font> out_img,
        <font color='#0000FF'>const</font> pyramid_type<font color='#5555FF'>&amp;</font> pyr
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// make sure requires clause is not broken
</font>        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font> <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> ,
            "<font color='#CC0000'>\t void pyramid_up()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid inputs were given to this function.</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t is_same_object(in_img, out_img):  </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>is_same_object</font><font face='Lucida Console'>(</font>in_img, out_img<font face='Lucida Console'>)</font>
            <font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>pyramid_up</font><font face='Lucida Console'>(</font>in_img, out_img, pyr, <font color='#BB00BB'>interpolate_bilinear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type,
        <font color='#0000FF'>typename</font> pyramid_type
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='pyramid_up'></a>pyramid_up</b> <font face='Lucida Console'>(</font>
        image_type<font color='#5555FF'>&amp;</font> img,
        <font color='#0000FF'>const</font> pyramid_type<font color='#5555FF'>&amp;</font> pyr
    <font face='Lucida Console'>)</font>
    <b>{</b>
        image_type temp;
        <font color='#BB00BB'>pyramid_up</font><font face='Lucida Console'>(</font>img, temp, pyr<font face='Lucida Console'>)</font>;
        temp.<font color='#BB00BB'>swap</font><font face='Lucida Console'>(</font>img<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='pyramid_up'></a>pyramid_up</b> <font face='Lucida Console'>(</font>
        image_type<font color='#5555FF'>&amp;</font> img
    <font face='Lucida Console'>)</font>
    <b>{</b>
        pyramid_down<font color='#5555FF'>&lt;</font><font color='#979000'>2</font><font color='#5555FF'>&gt;</font> pyr;
        <font color='#BB00BB'>pyramid_up</font><font face='Lucida Console'>(</font>img, pyr<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>struct</font> <b><a name='chip_dims'></a>chip_dims</b>
    <b>{</b>
        <b><a name='chip_dims'></a>chip_dims</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> rows_,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> cols_
        <font face='Lucida Console'>)</font> : rows<font face='Lucida Console'>(</font>rows_<font face='Lucida Console'>)</font>, cols<font face='Lucida Console'>(</font>cols_<font face='Lucida Console'>)</font> <b>{</b> <b>}</b>

        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> rows;
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> cols;
    <b>}</b>;

    <font color='#0000FF'>struct</font> <b><a name='chip_details'></a>chip_details</b>
    <b>{</b>
        <b><a name='chip_details'></a>chip_details</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> : angle<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>, rows<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>, cols<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font> <b>{</b><b>}</b>
        <b><a name='chip_details'></a>chip_details</b><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect_, <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> size<font face='Lucida Console'>)</font> : rect<font face='Lucida Console'>(</font>rect_<font face='Lucida Console'>)</font>,angle<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font> 
        <b>{</b> <font color='#BB00BB'>compute_dims_from_size</font><font face='Lucida Console'>(</font>size<font face='Lucida Console'>)</font>; <b>}</b>
        <b><a name='chip_details'></a>chip_details</b><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect_, <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> size, <font color='#0000FF'><u>double</u></font> angle_<font face='Lucida Console'>)</font> : rect<font face='Lucida Console'>(</font>rect_<font face='Lucida Console'>)</font>,angle<font face='Lucida Console'>(</font>angle_<font face='Lucida Console'>)</font> 
        <b>{</b> <font color='#BB00BB'>compute_dims_from_size</font><font face='Lucida Console'>(</font>size<font face='Lucida Console'>)</font>; <b>}</b>

        <b><a name='chip_details'></a>chip_details</b><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect_, <font color='#0000FF'>const</font> chip_dims<font color='#5555FF'>&amp;</font> dims<font face='Lucida Console'>)</font> : 
            rect<font face='Lucida Console'>(</font>rect_<font face='Lucida Console'>)</font>,angle<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>,rows<font face='Lucida Console'>(</font>dims.rows<font face='Lucida Console'>)</font>, cols<font face='Lucida Console'>(</font>dims.cols<font face='Lucida Console'>)</font> <b>{</b><b>}</b>
        <b><a name='chip_details'></a>chip_details</b><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect_, <font color='#0000FF'>const</font> chip_dims<font color='#5555FF'>&amp;</font> dims, <font color='#0000FF'><u>double</u></font> angle_<font face='Lucida Console'>)</font> : 
            rect<font face='Lucida Console'>(</font>rect_<font face='Lucida Console'>)</font>,angle<font face='Lucida Console'>(</font>angle_<font face='Lucida Console'>)</font>,rows<font face='Lucida Console'>(</font>dims.rows<font face='Lucida Console'>)</font>, cols<font face='Lucida Console'>(</font>dims.cols<font face='Lucida Console'>)</font> <b>{</b><b>}</b>

        rectangle rect;
        <font color='#0000FF'><u>double</u></font> angle;
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> rows; 
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> cols;

        <font color='#0000FF'>inline</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> <b><a name='size'></a>size</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> 
        <b>{</b>
            <font color='#0000FF'>return</font> rows<font color='#5555FF'>*</font>cols;
        <b>}</b>

    <font color='#0000FF'>private</font>:
        <font color='#0000FF'><u>void</u></font> <b><a name='compute_dims_from_size'></a>compute_dims_from_size</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> size
        <font face='Lucida Console'>)</font> 
        <b>{</b>
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> relative_size <font color='#5555FF'>=</font> std::<font color='#BB00BB'>sqrt</font><font face='Lucida Console'>(</font>size<font color='#5555FF'>/</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font><font face='Lucida Console'>)</font>rect.<font color='#BB00BB'>area</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            rows <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>relative_size <font color='#5555FF'>+</font> <font color='#979000'>0.5</font><font face='Lucida Console'>)</font>;
            cols  <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>size<font color='#5555FF'>/</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font><font face='Lucida Console'>)</font>rows <font color='#5555FF'>+</font> <font color='#979000'>0.5</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type1,
        <font color='#0000FF'>typename</font> image_type2
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='extract_image_chips'></a>extract_image_chips</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> image_type1<font color='#5555FF'>&amp;</font> img,
        <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>chip_details<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> chip_locations,
        dlib::array<font color='#5555FF'>&lt;</font>image_type2<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> chips
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// make sure requires clause is not broken
</font><font color='#0000FF'>#ifdef</font> ENABLE_ASSERTS
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> chip_locations.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>DLIB_CASSERT</font><font face='Lucida Console'>(</font>chip_locations[i].<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                         chip_locations[i].rect.<font color='#BB00BB'>is_empty</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font>,
            "<font color='#CC0000'>\t void extract_image_chips()</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t Invalid inputs were given to this function.</font>"
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t chip_locations[</font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font>i<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font>"<font color='#CC0000'>].size():            </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> chip_locations[i].<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
            <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t chip_locations[</font>"<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font>i<font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font>"<font color='#CC0000'>].rect.is_empty(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> chip_locations[i].rect.<font color='#BB00BB'>is_empty</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
            <font face='Lucida Console'>)</font>;
        <b>}</b>
<font color='#0000FF'>#endif</font> 

        pyramid_down<font color='#5555FF'>&lt;</font><font color='#979000'>2</font><font color='#5555FF'>&gt;</font> pyr;
        <font color='#0000FF'><u>long</u></font> max_depth <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
        <font color='#009900'>// If the chip is supposed to be much smaller than the source subwindow then you
</font>        <font color='#009900'>// can't just extract it using bilinear interpolation since at a high enough
</font>        <font color='#009900'>// downsampling amount it would effectively turn into nearest neighbor
</font>        <font color='#009900'>// interpolation.  So we use an image pyramid to make sure the interpolation is
</font>        <font color='#009900'>// fast but also high quality.  The first thing we do is figure out how deep the
</font>        <font color='#009900'>// image pyramid needs to be.
</font>        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> chip_locations.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'><u>long</u></font> depth <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            rectangle rect <font color='#5555FF'>=</font> pyr.<font color='#BB00BB'>rect_down</font><font face='Lucida Console'>(</font>chip_locations[i].rect<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>area</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> chip_locations[i].<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <b>{</b>
                rect <font color='#5555FF'>=</font> pyr.<font color='#BB00BB'>rect_down</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
                <font color='#5555FF'>+</font><font color='#5555FF'>+</font>depth;
            <b>}</b>
            max_depth <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>depth,max_depth<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#009900'>// now make an image pyramid
</font>        dlib::array<font color='#5555FF'>&lt;</font>image_type1<font color='#5555FF'>&gt;</font> <font color='#BB00BB'>levels</font><font face='Lucida Console'>(</font>max_depth<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>levels.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
            <font color='#BB00BB'>pyr</font><font face='Lucida Console'>(</font>img,levels[<font color='#979000'>0</font>]<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>1</font>; i <font color='#5555FF'>&lt;</font> levels.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
            <font color='#BB00BB'>pyr</font><font face='Lucida Console'>(</font>levels[i<font color='#5555FF'>-</font><font color='#979000'>1</font>],levels[i]<font face='Lucida Console'>)</font>;

        std::vector<font color='#5555FF'>&lt;</font>dlib::vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font> from, to;

        <font color='#009900'>// now pull out the chips
</font>        chips.<font color='#BB00BB'>resize</font><font face='Lucida Console'>(</font>chip_locations.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> chips.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            chips[i].<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>chip_locations[i].rows, chip_locations[i].cols<font face='Lucida Console'>)</font>;

            <font color='#009900'>// figure out which level in the pyramid to use to extract the chip
</font>            <font color='#0000FF'><u>int</u></font> level <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
            rectangle rect <font color='#5555FF'>=</font> chip_locations[i].rect;
            <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>pyr.<font color='#BB00BB'>rect_down</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>.<font color='#BB00BB'>area</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> chip_locations[i].<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#5555FF'>+</font><font color='#5555FF'>+</font>level;
                rect <font color='#5555FF'>=</font> pyr.<font color='#BB00BB'>rect_down</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
            <b>}</b>

            <font color='#009900'>// find the appropriate transformation that maps from the chip to the input
</font>            <font color='#009900'>// image
</font>            from.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            to.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            from.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font>chips[i]<font face='Lucida Console'>)</font>.<font color='#BB00BB'>tl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;  to.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>rotate_point<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font color='#BB00BB'>center</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>tl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,chip_locations[i].angle<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            from.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font>chips[i]<font face='Lucida Console'>)</font>.<font color='#BB00BB'>tr_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;  to.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>rotate_point<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font color='#BB00BB'>center</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>tr_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,chip_locations[i].angle<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            from.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font>chips[i]<font face='Lucida Console'>)</font>.<font color='#BB00BB'>bl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;  to.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>rotate_point<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font color='#BB00BB'>center</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>bl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,chip_locations[i].angle<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            point_transform_affine trns <font color='#5555FF'>=</font> <font color='#BB00BB'>find_affine_transform</font><font face='Lucida Console'>(</font>from,to<font face='Lucida Console'>)</font>;

            <font color='#009900'>// now extract the actual chip
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>level <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>
                <font color='#BB00BB'>transform_image</font><font face='Lucida Console'>(</font>img,chips[i],<font color='#BB00BB'>interpolate_bilinear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,trns<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>else</font>
                <font color='#BB00BB'>transform_image</font><font face='Lucida Console'>(</font>levels[level],chips[i],<font color='#BB00BB'>interpolate_bilinear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,trns<font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type1,
        <font color='#0000FF'>typename</font> image_type2
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='extract_image_chip'></a>extract_image_chip</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> image_type1<font color='#5555FF'>&amp;</font> img,
        <font color='#0000FF'>const</font> chip_details<font color='#5555FF'>&amp;</font> location,
        image_type2<font color='#5555FF'>&amp;</font> chip
    <font face='Lucida Console'>)</font>
    <b>{</b>
        std::vector<font color='#5555FF'>&lt;</font>chip_details<font color='#5555FF'>&gt;</font> <font color='#BB00BB'>chip_locations</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>,location<font face='Lucida Console'>)</font>;
        dlib::array<font color='#5555FF'>&lt;</font>image_type2<font color='#5555FF'>&gt;</font> chips;
        <font color='#BB00BB'>extract_image_chips</font><font face='Lucida Console'>(</font>img, chip_locations, chips<font face='Lucida Console'>)</font>;
        chips[<font color='#979000'>0</font>].<font color='#BB00BB'>swap</font><font face='Lucida Console'>(</font>chip<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<b>}</b>

<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_INTERPOlATION__
</font>

</pre></body></html>